import { fromJS }  from 'immutable';
import * as constants from './constants';

const defaultState = fromJS({
    topicList:[],
    articleList:[],
    recommendList:[],
    articlePage:1,
    showScroll:false,
});

const changeHomeDate = (state ,action) =>{

  return state.merge({
    topicList:fromJS(action.topicList),
    articleList:fromJS(action.articleList),
    recommendList:fromJS(action.recommendList),
  });
}


const addHomeDate = (state ,action) =>{

  return   state.merge({
       articleList: state.get('articleList').concat(fromJS(action.data)),
       articlePage:action.nextPage
     });
}


export default (state = defaultState ,action) =>{
    switch(action.type){
        case constants.HOME_CHANGE_DATA:
          return  changeHomeDate(state,action);
         case constants.ADD_HOME_DATA:
        return   addHomeDate(state,action);
        case constants.HOME_LISTENER_SCROLL_TOP:
         return state.set('showScroll',action.show);

      default:
      return state;
    }

}
